package D240425;

public class Sequence {
    static long result;
    // 公式法
    public static int add(int a) {
        return (1 + a) * a / 2;
    }
    // 递归法
    public static long addRecursion(int a) {
        if (a == 1) {
            return 1;
        } else {
            result = add(a - 1) + a;
            return result;
        }
    }
    // 递归法求阶乘
    public static long factorial(long a) {
        if (a == 1 || a == 0) {
            return 1;
        } else {
            result = factorial(a - 1) * a;
            return result;
        }
    }
    public static void main(String[] args) {
        System.out.println(Sequence.add(100));
        System.out.println(Sequence.addRecursion(100));
        System.out.println(Sequence.factorial(20));
    }
}
